package com.sduonline.isdapp.config;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.Properties;

public class BaseConfig {

	/**
	 * 项目实际所在路径
	 */
	public static String ROOT;

	static {
		ROOT = BaseConfig.class.getResource("/").getPath();
		ROOT = ROOT.substring(0, ROOT.length() - 17);
		try {
			ROOT = URLDecoder.decode(ROOT, "UTF-8");
		} catch (UnsupportedEncodingException e) {
			ROOT = ROOT.replace("%20", " ");
			e.printStackTrace();
		}
		System.out.println("config root :" + ROOT);
	}

	/**
	 * 项目访问的项目名
	 */
	public static String PRO_NAME = "/isdunews";

	static {
		try {
			Properties props = new Properties();
			String srcPath = BaseConfig.class.getResource("/").getPath();
			try {
				srcPath = URLDecoder.decode(srcPath, "UTF-8");
			} catch (UnsupportedEncodingException e) {
				srcPath = ROOT.replace("%20", " ");
				e.printStackTrace();
			}
			props.load(new FileInputStream(new File(srcPath + "/" + "ishanda.properties")));
			PRO_NAME = props.getProperty("project_name", "/isdunews");
			System.out.println("init PRO_NAME :" + PRO_NAME);
		} catch (IOException e) {
			e.printStackTrace();
		}

	}

	public static void main(String[] args) {
		try {
			Properties props = new Properties();
			String srcPath = BaseConfig.class.getResource("/").getPath();
			try {
				srcPath = URLDecoder.decode(srcPath, "UTF-8");
			} catch (UnsupportedEncodingException e) {
				srcPath = ROOT.replace("%20", " ");
				e.printStackTrace();
			}
			props.load(new FileInputStream(new File(srcPath + "/" + "ishanda.properties")));
			System.out.println(props.getProperty("project_name"));
		} catch (IOException e) {
			e.printStackTrace();
		}

	}

}